#!/usr/bin/env python

'''
Created on Jun 21, 2012
Script to crypt password to be used in configuration. 


@author: vukasin.n@gmail.com
# According to tutorial: http://www.codekoala.com/blog/2009/aes-encryption-python-using-pycrypto/
'''

from Crypto.Cipher import AES
import base64
import os
import sys

s1 = '$!F*Us'
e2 = 'ju^3)('
c3 = '^%^##!'
r4 = '@#HHAW'
tr = s1 + e2
rt = c3 + r4
ret = tr + rt

PADDING = '`'

len2add = 16 - len(sys.argv[1])

newLen = sys.argv[1] + len2add * PADDING

secret = ret

cipher = AES.new(secret,AES.MODE_CFB)

encoded = base64.b64encode(cipher.encrypt(newLen))
print 'Encrypted password:  ' + encoded
